const express = require('express')
const router = express.Router()
//连接数据库
const db = require('../db')
db('fontdb', () => {
    console.log('数据库连接成功')
}, () => {
    console.log('数据库连接失败')
})
// 定义模型
const Navs = require('../models/NavModel');
const User = require('../models/UserModel');
const Country = require('../models/createNavModel')
//向三级联动集合中插入数据
router.get('/countries', async (req, res) => {
    const newCountry = new Country({
        name: "中国",
        children: [
            {
                name: "北京市",
                children: [
                    { name: "东城区" },
                    { name: "西城区" }
                ]
            },
            {
                name: "上海市",
                children: [
                    { name: "黄浦区" },
                    { name: "徐汇区" }
                ]
            }
        ]
    });

    const saveCountry = await newCountry.save();
    res.status(201).json(saveCountry);
});
//获取导航
// router.get('/product/getBaseCategoryList', async (req, res) => {
//     await console.log('请求nav联动');
//     res.end('jj');
// });
// 创建插入用户的路由
router.get('/users', async (req, res) => {
    const newUser = new User(req.query);
    const savedUser = await newUser.save();
    res.status(201).send(savedUser);
});
module.exports = router